package com.qfedu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.CourseDao;
import com.qfedu.entity.Course;
import com.qfedu.entity.ResponseData;
import com.qfedu.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseDao courseDao;

    @Override
    public ResponseData<List<Course>> getCourseList(int pageIndex,int pageSize) {

        Page<Course> page = PageHelper.startPage(pageIndex, pageSize);
        List<Course> courseList = courseDao.getCourseList();
        PageInfo pageInfo = new PageInfo(courseList);
        int total = (int)pageInfo.getTotal();
        ResponseData<List<Course>> responseData = new ResponseData<>();
        responseData.setCode(0);
        responseData.setData(courseList);
        responseData.setMsg(ResponseData.SUCCESS_MSG);
        responseData.setCount(total);
        return responseData;
    }

    @Override
    public int deleteCourseListById(int id) {
        return courseDao.deleteCourseListById(id);
    }
    @Override
    public int updateCourse(Course course){
        return courseDao.updateCourse(course);
    }

    @Override
    public int addCourse(Course course) {
        return courseDao.addCourse(course);
    }
}
